<template>
 <el-card>
 <!-- 表格 -->
  <el-table :data="tableData"
   border
   stripe
   style="width: 100%">
 <!-- 选择框 -->
   
   <el-table-column type="selection"  width="50"  v-if='select'  @selection-change="handleSelectionChange"
   :multipleSelection='multipleSelection'
   >
    
   </el-table-column>
   
   <!--序号 -->
   <el-table-column  type='index' width="80" v-if="showIndex"  label="序号" >
    </el-table-column>
    
 
     <!-- 特殊处理列表 switch -->
    <template v-for="value in tableLabel ">
      <el-table-column  v-if="value.type==='function'" :key="value.id" :prop='value.prop'
      :label='value.label' width="180" >
      <!-- vue3里不适应slot-scope ,使用#default="scope"-->
      <template #default="scope">
      
 
    <el-switch
    v-model="scope.row.mg_state"
    class="ml-2"
    style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
  />
       
      </template>
       </el-table-column> 
       <!-- 特殊处理列表 操作，不会使用插槽 -->
        <el-table-column  v-else-if="value.type==='opt'" :key="value.id" :prop='value.prop'
       :label='value.label' width="180" >
      <!-- vue3里不适应slot-scope ,使用#default="scope"-->
      <template #default="scope">
         <el-button size="small"
         type='primary'
          @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button
        >
        <el-button
          size="small"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        >
    
      </template>
      <!-- 普通列表 -->
       </el-table-column>
       <el-table-column  v-else  :key="value.id"
        :prop='value.prop' 
        :label='value.label'
        >
        </el-table-column> 
     </template>
   
  </el-table>
  <!-- 分页 -->
  <div class="demo-pagination-block">
    
    <el-pagination
      v-model:currentPage="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[1, 5, 10, 15]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
 </el-card>
  
</template>
<script lang="ts" setup>
import {ref,defineEmits,defineProps,} from 'vue'
 
const props=defineProps({
    
    
 
    tableData:{
        type:Array,
        default:[]
    },
    tableLabel:{
          type:Object,
          default:[]
    },
    select:{
        type:Boolean,
        default:false
    },
    showIndex:{
        type:Boolean,
        default:false
    },
  currentPage:{
  type:Number,
  default:0
  },
    pageSize:{
    type:Number,
    default:0
   },
   total:{
    type:Number,
    default:0
},
})
 
 
//注册emit
const emit = defineEmits<{
  (e: "handleSizeChange", val: number): void;
  (e: "handleCurrentChange", val: number): void;
}>();
 
//定义emit的值
const handleSizeChange = (val: any) => {
  emit("handleSizeChange", val);
};
const handleCurrentChange = (val: any) => {
  emit("handleCurrentChange", val);
};
 
 
 
  
 
 
</script>
<style scoped>
.demo-pagination-block{
  margin-top: 20px;
  text-align: center;
}
.el-pagination{
  text-align: center;
}
</style>